import React  from 'react';
import {Table} from 'antd';

const renderContent = (value, row, index) => {
	const obj = {
		children: value,
		props: {},
	};
	
	if (index === 0 ) {
		obj.props.rowSpan = 2	;
	}
	if (index === 1 ) {
		obj.props.rowSpan = 0	;
	}
	if (index === 2 ) {
		obj.props.rowSpan = 2	;
	}
	if (index === 3 ) {
		obj.props.rowSpan = 0	;
	}
	if (index === 4 ) {
		obj.props.rowSpan = 2	;
	}
	if (index === 5 ) {
		obj.props.rowSpan = 0	;
	}
	if (index === 6 ) {
		obj.props.rowSpan = 2	;
	}
	if (index === 7 ) {
		obj.props.rowSpan = 0	;
	}
	
	return obj;
};
const Vartable =({dataSource})=>{
	console.log(`data--------`,dataSource[0])
	const columns = [
	{
		title: '期间',
		dataIndex: 'period',
		key: 'period',
		render: renderContent,
	},
	{
		title: '项目',
		dataIndex: 'object',
		key: 'object',
	},
	{
		title:`VaR（${dataSource[0].confidenceLevel},5D)`,
		dataIndex:'confidenceLevel',
		key:'confidenceLevel',
		children: [
			{
				title: 'VaR（%)',
				dataIndex: 'varRate_1',
				key: 'varRate_1',
			},
			{
				title: 'VaR（万元）',
				dataIndex: 'varValue_1',
				key: 'varValue_1',
			},
			{
				title: 'ES（%）',
				dataIndex: 'esRate_1',
				key: 'esRate_1',
			},
			{
				title: 'ES（万元）',
				dataIndex: 'esValue_1',
				key: 'esValue_1',
			},
		]
	},
	{
		title:`VaR（${dataSource[1].confidenceLevel},5D)`,
		children: [
			{
				title: 'VaR（%)',
				dataIndex: 'varRate_2',
				key: 'varRate_2',
			},
			{
				title: 'VaR（万元）',
				dataIndex: 'varValue_2',
				key: 'varValue_2',
			},
			{
				title: 'ES（%）',
				dataIndex: 'esRate_2',
				key: 'esRate_2',
			},
			{
				title: 'ES（万元）',
				dataIndex: 'esValue_2',
				key: 'esValue_2',
			},
		]
	}
]
	return (
			<div >
				<Table
					dataSource={dataSource}
					rowKey="id"
					columns={columns} 
					pagination={false} 
					size="small"
					bordered
				/>
			</div>
		)
}

// const Vartable =(props)=>(
// 	<div>
// 		<Table
// 			{...props}
// 			rowKey="id"
// 			columns={columns}
// 			pagination={false}
// 			size="small"
// 			bordered
// 		/>
// 	</div>
// )

Vartable.propTypes={
}

export default Vartable